﻿@using Didsoft.Mvc.Helpers
@model SIOGDE.AccesoDatos.Entidades.PersonaArma
@{
    string redireccion = ViewBag.Redireccion;
    Layout = "../Shared/_LayoutJtable.cshtml";   
}

<link href="~/Content/DataForm.css" rel="stylesheet"/>
@section LocalStyles
{
    <link href="~/Content/themes/redmond/jquery-ui-1.8.16.custom.css" rel="stylesheet" />   
}
   
<script>
    $(function () {
        $("#btnCommon").click(function () {
            var config = getArma();
            var json = JSON.stringify(config);
            //alert(json);
            $.ajax({
                url: 'JSONCreate',
                contentType: 'application/json',
                type: 'POST',
                dataType: 'json',
                data: json
            })
           .success(function (result) {               
               if (result.Result == 'ERROR')
                   alert(result.Message);
               else {
                   
                   LoadDataTable();
                   clearFields();
               }
           })
           .error(function (xhr, status) {
               //alert(xhr.Message);
               alert('ups!!!, Servicio No disponible')
           });

        });
    });

    function getArma() {
        var arma = {}        
        arma.PersonaId_FK = $("#PersonaId_FK").val();
        arma.ArmaId_FK = $("#ArmaId_FK").val();
        arma.MotivoActualizacion = $("#MotivoActualizacion").val();
        arma.Descripcion = $("#MotivoActualizacion").val();
        arma.EsActual = 'true';
        return arma;
    }

    function clearFields()
    {
       

        $("#ArmaId_FK").val('');
        $("#ArmaId_FK_autocomplete").val('');
        
        $("#MotivoActualizacion").val('');    

    }


    function LoadDataTable() {
        $('#MyTableContainer').jtable('load', { personaId: $('#PersonaId_FK').val() });
    }


</script>


<div class="box common"  id="myDataForm">
     <div class="header">Arma de : @Model.Persona.NombreCompleto</div>
    @Html.HiddenFor(model => model.PersonaId_FK)
    <fieldset class="boxBody">
         @Html.HiddenFor(model => model.PersonaId_FK)

         <ul id="list" class="inputcontrols-grid">
             <li>
                  @Html.LabelFor(model => model.Arma)
                @Html.AutocompleteFor(model => model.ArmaId_FK, "Id", Url.Action("SearchByFilter","Arma"))
            </li>

             <li data-id="2">
                @Html.LabelFor(model => model.MotivoActualizacion)
                @Html.EditorFor(model => model.MotivoActualizacion)
        </ul>
        <input type="submit" id="btnCommon" class="button medium green" value="Guardar Configuracion Arma"/>
    </fieldset>

<div id="MyTableContainer"></div>
<script type="text/javascript">
    $(document).ready(function () {
        $('#MyTableContainer').jtable({
            title: 'Persona Arma',
            paging: true,
            pageSize: 40,
            sorting: true,
            defaultSorting: 'Id ASC',
            actions: {
                listAction: '@Url.Action("JSONPagedListByPersona")',                
                updateAction: '@Url.Action("JSONUpdate")',
                deleteAction: '@Url.Action("JSONDelete")'
            },
            fields:
            {
                Id: {
                    key: true,
                    create: false,
                    edit: false,
                    list: false
                },
                PersonaId_FK:
                {
                    type: 'hidden',
                    default: $('#PersonaId_FK')
                }
             ,
                ArmaId_FK: {
                    title: 'Arma',
                    create: true,
                    edit: true,
                    list: true,
                    options: '@Url.Action("../Arma/JSONGetElementsForDropDownList")'
                }
                ,
                EsActual: {
                    title: 'EsActual',
                    create: true,
                    edit: true,
                    list: true,
                    type: 'checkbox',
                    values: { 'false': 'Desactivado', 'true': 'Activado' },
                    sorting: false
                }
             ,
                MotivoActualizacion: {
                    title: 'MotivoActualizacion',
                    create: true,
                    edit: true,
                    list: true,
                    sorting: false
                }
             ,
               
                FechaActualizacion: {
                    title: 'FechaActualizacion',
                    create: true,
                    edit: true,
                    list: true,
                    type: 'date',
                    displayFormat: 'dd/mm/yy',
                    inputClass: 'validate[required]',
                    sorting: false
                }
             ,
                ActualizadoPor: {
                    title: 'ActualizadoPor',
                    create: true,
                    edit: true,
                    list: true,
                    sorting: false
                }
             

         },
            formCreated: function (event, data) { data.form.validationEngine(); },
            formSubmitting: function (event, data) { return data.form.validationEngine('validate'); },
            formClosed: function (event, data) { data.form.validationEngine('hide'); data.form.validationEngine('detach'); }
        });
        LoadDataTable();
    });
</script>


<footer>
    <input type="button" class="btnCancel" value="Regresar a Ficha Personal" onclick="history.go(-1);" />
</footer>
</div>

@section Scripts{@Scripts.Render("~/bundles/jqueryval")

    }
